package app.cn.com.school.tools

import android.graphics.Color
import android.os.CountDownTimer
import android.text.Spannable
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import android.widget.TextView

/**
 * Created by Administrator on 2017/11/1 0001.
 */
open class CountDownTimerUtils(var mTextView: TextView, millisInFuture: Long, countDownInterval: Long) : CountDownTimer(millisInFuture, countDownInterval) {

    override fun onFinish() {
        mTextView.text = "重新获取验证码"
        mTextView.isClickable = true
    }

    override fun onTick(millisUntilFinished: Long) {
        mTextView.isClickable = false
        mTextView.text = (millisUntilFinished / 1000).toString() + "s后重新获取"
//        mTextView.setBackgroundResource(R.drawable.edittext_bg)  //设置按钮为灰色
        var spannableString = SpannableString(mTextView.text.toString())
        var span = ForegroundColorSpan(Color.RED)
        spannableString.setSpan(span, 0, 2, Spannable.SPAN_INCLUSIVE_EXCLUSIVE)
        mTextView.text = spannableString


    }
}